<?php

/**
 * +----------------------------------------------------------------------
 * | 后台页面
 * +----------------------------------------------------------------------
 *                                            ...     .............
 *                                          ..   .:!o&*&&&&&ooooo&; .
 *                                        ..  .!*%*o!;.
 *                                      ..  !*%*!.      ...
 *                                     .  ;$$!.   .....
 *                          ........... .*#&   ...
 *                                     :$$: ...
 *                          .;;;;;;;:::#%      ...
 *                        . *@ooooo&&&#@***&&;.   .
 *                        . *@       .@%.::;&%$*!. . .
 *          ................!@;......$@:      :@@$.
 *                          .@!   ..!@&.:::::::*@@*.:..............
 *        . :!!!!!!!!!!ooooo&@$*%%%*#@&*&&&&&&&*@@$&&&oooooooooooo.
 *        . :!!!!!!!!;;!;;:::@#;::.;@*         *@@o
 *                           @$    &@!.....  .*@@&................
 *          ................:@* .  ##.     .o#@%;
 *                        . &@%..:;@$:;!o&*$#*;  ..
 *                        . ;@@#$$$@#**&o!;:   ..
 *                           :;:: !@;        ..
 *                               ;@*........
 *                       ....   !@* ..
 *                 ......    .!%$! ..     | AUTHOR: dfer
 *         ......        .;o*%*!  .       | EMAIL: df_business@qq.com
 *                .:;;o&***o;.   .        | QQ: 3504725309
 *        .;;!o&****&&o;:.    ..          | WEBSITE: http://www.dfer.site
 * +----------------------------------------------------------------------
 *
 */

namespace plugins\dfer_thinkcmf_tools\controller;

use plugins\dfer_thinkcmf_tools\logic\MenuLogic;
use app\admin\model\AdminMenuModel;
use app\admin\model\AuthRuleModel;
use think\facade\Cache;
use tree\Tree;
use mindplay\annotations\Annotations;

class AdminMenuController extends AdminBaseController
{
	/**
	 * 更新所有菜单	 
	 */
	public function getActionsAll()
	{
		$update_app_list = $this->config['update_app_list'];
		if ($update_app_list) {
			$update_app_list_arr = explode(',', $update_app_list);
			$apps = $update_app_list_arr;
		} else {
			$apps = cmf_scan_dir($this->app->getAppPath() . '*', GLOB_ONLYDIR);
		}
		$apps = array_values(array_unique($apps));
		// var_dump($apps);die;

		$app = $this->request->param('app', '');
		if (empty($app)) {
			$app = $apps[0];
		}

		if (!in_array($app, $apps)) {
			$this->error('应用' . $app . '不存在!');
		}
		// var_dump($app);
		$newMenus  = MenuLogic::importMenusAll($app);
		$index     = array_search($app, $apps);
		$nextIndex = $index + 1;
		$nextIndex = $nextIndex >= count($apps) ? 0 : $nextIndex;
		if ($nextIndex) {
			$this->assign("next_app", $apps[$nextIndex]);
		}
		$this->assign("app", $app);
		$this->assign("new_menus", $newMenus);

		Cache::clear('admin_menus'); // 删除后台菜单缓存

		return $this->fetch(__FUNCTION__);
	}
}
